import { getToken, setToken } from '@/unit/cookies'
const state = () =>({
  name:'',
  token: getToken(),
  roles:''
})

const mutations = {
  SET_TOKEN(state, token){
    state.token = token
  },
  SET_ROLES(state, roles){
    state.roles = roles
  },
  SET_NAME(state, name){
    state.name = name
  }
}

const actions = {
  login({commit}){
    const data = {
      name: 'hk',
      token: '123456',
      roles:'admin'
    }
    commit('SET_TOKEN', data.token)
    commit('SET_ROLES', data.roles)
    commit('SET_NAME', data.name)
    setToken(data.token)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}